package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ByteArrayContainsOnlyZeroes {
	public static void main(String[] argv) {
		byte[] array = new byte[]{34, 0};
		byte[] array1 = new byte[]{0, 0};
		System.out.println("字节数组" + Arrays.toString(array) + "是否仅包含0?  " + byteArrayBlank(array));
		System.out.println("字节数组" + Arrays.toString(array1) + "是否仅包含0? " + byteArrayBlank(array1));
	}

	private static boolean byteArrayBlank(byte[] array) {
		return byteArraySliceBlank(array, 0, array.length);
	}


	private static boolean byteArraySliceBlank(byte[] array, int start, int length) {
		for (int i = start; i < start + length; i++) {
			if (array[i] != 0) {
				return false;
			}
		}
		return true;
	}
}
